package com.orange.studio.dbk.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.orange.studio.dbk.R;

public class BaseActivity extends FragmentActivity  implements OnClickListener, OnPageChangeListener{
	private LinearLayout mViewContainer = null;

	private View menuBottomLeft = null;
	private View menuBottomMiddle = null;
	private View menuBottomRight = null;
	private View mFooterView=null;
	
	protected int currentView = R.id.menuMiddle;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.base_activity_layout);
		initView();
		initListener();
	}
	private void initView() {
		mViewContainer = (LinearLayout) findViewById(R.id.mViewContainer);
		mFooterView=(LinearLayout)findViewById(R.id.appFooter);
		
		menuBottomLeft = (LinearLayout) findViewById(R.id.menuLeft);
		menuBottomMiddle = (LinearLayout) findViewById(R.id.menuMiddle);
		menuBottomRight = (LinearLayout) findViewById(R.id.menuRight);
		
		setDefaultMenuBackground();
	}

	private void initListener() {

		menuBottomLeft.setOnClickListener(this);
		menuBottomMiddle.setOnClickListener(this);
		menuBottomRight.setOnClickListener(this);

	}
	protected void showFooterView(boolean isShow){
		mFooterView.setVisibility(isShow?View.VISIBLE:View.GONE);
	}
	protected void setMainView(int resId) {
		LayoutInflater inflater = LayoutInflater.from(this);
		inflater.inflate(resId, mViewContainer);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {		
		case R.id.menuLeft:
			currentView = R.id.menuLeft;
			break;
		case R.id.menuMiddle:
			currentView = R.id.menuMiddle;
			break;
		case R.id.menuRight:
			currentView = R.id.menuRight;
			break;
		default:
			break;
		}
		switchLayout(currentView);
	}

	private void setDefaultMenuBackground() {
		menuBottomLeft
				.setBackgroundResource(R.drawable.menu_bottom_background_selected);
		menuBottomMiddle
				.setBackgroundResource(R.drawable.menu_bottom_background_normal);
		menuBottomRight
				.setBackgroundResource(R.drawable.menu_bottom_background_normal);
	}

	protected void switchLayout(int id) {
		switch (id) {
		case R.id.menuLeft:
			menuBottomLeft
					.setBackgroundResource(R.drawable.menu_bottom_background_selected);
			menuBottomMiddle
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			menuBottomRight
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			break;
		case R.id.menuMiddle:
			menuBottomLeft
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			menuBottomMiddle
					.setBackgroundResource(R.drawable.menu_bottom_background_selected);
			menuBottomRight
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			break;
		case R.id.menuRight:
			menuBottomLeft
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			menuBottomMiddle
					.setBackgroundResource(R.drawable.menu_bottom_background_normal);
			menuBottomRight
					.setBackgroundResource(R.drawable.menu_bottom_background_selected);
			break;
		default:
			break;
		}
	}
	
	@Override
	public void onPageScrollStateChanged(int arg0) {
		
	}
	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		
	}
	@Override
	public void onPageSelected(int arg0) {
		
	}

}
